<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Service for the shift roles
 *
 * @category	RedCross
 * @package		Core_Service
 */
class Core_Service_ShiftRole extends RedCross_Service_ServiceAbstract
{
	public function __construct(Core_Gateway_ShiftRole $gateway)
	{
		parent::__construct($gateway, 'Core_Model_ShiftRole');
	}    

	//TODO: this should be named create
	public function createShiftRole(Core_Model_ShiftRole $shiftrole){
		$this->save($shiftrole);
	}

	//TODO this should be named fetchByShift
	public function getAllRolesForShift($id){

		return $this->getGateway()->getAllRolesForShift($id);
	}

	public function replaceRole($role, $newMemberId)
	{
	    $this->checkAcl('replaceRole');
        if ($role['Member']['id'] === $newMemberId) {
        	return;
        }
        return $this->getGateway()->replaceRole($role, $newMemberId);
	}

    public function confirmNotification(Core_Model_ShiftRole $shiftRole)
    {
        $this->checkAcl('confirmNotification');

		$date = new RedCross_Date();
		$shiftRole->notification_confirmed_time = $date->export();
        return $this->save($shiftRole);
    }

    public function fetchForMemberRoleTable($shiftId)
    {
        return $this->getGateway()->fetchForMemberRoleTable($shiftId);
    }

    public function fetchMemberNameAndRoleName($shiftRoleId)
    {
        return $this->getGateway()->fetchMemberNameAndRoleName($shiftRoleId);
    }

    public function fetchById($shiftRoleId)
    {
        return $this->getGateway()->fetchById($shiftRoleId);
    }

}
